package com.luxsoft.sw3.kio.ui.form;

import javax.swing.JComponent;
import javax.swing.JTextField;

import com.jgoodies.forms.builder.DefaultFormBuilder;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.uifextras.panel.HeaderPanel;
import com.luxsoft.siipap.swing.binding.Binder;
import com.luxsoft.siipap.swing.form2.AbstractForm;
import com.luxsoft.siipap.swing.form2.DefaultFormModel;
import com.luxsoft.siipap.swing.form2.IFormModel;
import com.luxsoft.sw3.gasoc.model.Instructor;
import com.luxsoft.sw3.services.Services;




/**
 * Forma para el mantenimiento de Instructores desde el punto de venta
 * 
 * @author Ruben Cancino
 *
 */
public class InstructorForm extends AbstractForm{
	
	
	

	public InstructorForm(IFormModel model) {
		super(model);
		setTitle("Mantenimiento de Instructor");
	}

	@Override
	protected JComponent buildHeader() {
		if(model.getValue("id")!=null)
			return new HeaderPanel("Registro de Instructor nuevo ","");
		return null;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected JComponent buildFormPanel() {
		final FormLayout layout=new FormLayout(
				"p,2dlu,p:g(.5), 2dlu," +
				"p,2dlu,p:g(.5)"
				,""
				);
		final DefaultFormBuilder builder=new DefaultFormBuilder(layout);
		builder.setDefaultDialogBorder();
		
		if(model.isReadOnly()){
			builder.append("Id",getControl("id"),true);
		}
		
		builder.append("Apellido P",getControl("apellidoP"));
		builder.append("Apellido M",getControl("apellidoM"));
		builder.append("Nombre(s)",getControl("nombres"),5);
		builder.nextLine();
		builder.append("Email",getControl("email"),5);		
		builder.append("Telefono",getControl("telefono1"));
		builder.append("Telefono 2",getControl("telefono2"));
		return builder.getPanel();
	}
	
	

	
	@Override
	protected JComponent createCustomComponent(String property) {		
		if("nombre".equals(property) || "nombres".equals(property) || "apellidoP".equals(property) || "apellidoM".equals(property)){
			JTextField tf=Binder.createMayusculasTextField(model.getComponentModel(property),true);
			tf.setColumns(20);
			return tf;
		}
		return null;
	}
	
	
	
	
	/**
	 * Prueba local en el EDT
	 * 
	 * @param args
	 * 
	 */
	public static void main(String[] args) {
		javax.swing.SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				com.luxsoft.siipap.swing.utils.SWExtUIManager.setup();
				Instructor socio=new Instructor();
				DefaultFormModel model=new DefaultFormModel(socio);
				InstructorForm form=new InstructorForm(model);
				form.open();
				if(!form.hasBeenCanceled()){
					Services.getInstance().getHibernateTemplate().merge(model.getBaseBean());
				}
				System.exit(0);
			}

		});
	}
}
